package Endereco;
import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import Bairro.Bairro;

@Entity
@Table (name = "tab_endereco")
public class Endereco implements Serializable{
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue (strategy = GenerationType.IDENTITY)
	private Integer codEndereco;
	@Column (length = 50)
	private String dscLogradouro;
	@Column (length = 50)
	private String logNum; 
	@Column (length = 30)
	private String logComplemento;
	@Column (length = 50)
	private String tipoLog;
	private int CEP;
	@ManyToOne (fetch = FetchType.EAGER, cascade = {CascadeType.MERGE, CascadeType.PERSIST})
	private Bairro bairro;
	
	public Endereco() {
		super();
	}

	public Endereco(String dscLogradouro, String logNum, String logComplemento,
			String tipoLog, int cEP, Bairro bairro) {
		super();
		this.dscLogradouro = dscLogradouro;
		this.logNum = logNum;
		this.logComplemento = logComplemento;
		this.tipoLog = tipoLog;
		CEP = cEP;
		this.bairro = bairro;
	}

	public Integer getCodEndereco() {
		return codEndereco;
	}

	public void setCodEndereco(Integer codEndereco) {
		this.codEndereco = codEndereco;
	}

	public String getDscLogradouro() {
		return dscLogradouro;
	}

	public void setDscLogradouro(String dscLogradouro) {
		this.dscLogradouro = dscLogradouro;
	}

	public String getLogNum() {
		return logNum;
	}

	public void setLogNum(String logNum) {
		this.logNum = logNum;
	}

	public String getLogComplemento() {
		return logComplemento;
	}

	public void setLogComplemento(String logComplemento) {
		this.logComplemento = logComplemento;
	}

	public String getTipoLog() {
		return tipoLog;
	}

	public void setTipoLog(String tipoLog) {
		this.tipoLog = tipoLog;
	}

	public int getCEP() {
		return CEP;
	}

	public void setCEP(int cEP) {
		CEP = cEP;
	}

	public Bairro getBairro() {
		return bairro;
	}

	public void setBairro(Bairro bairro) {
		this.bairro = bairro;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((codEndereco == null) ? 0 : codEndereco.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Endereco other = (Endereco) obj;
		if (codEndereco == null) {
			if (other.codEndereco != null)
				return false;
		} else if (!codEndereco.equals(other.codEndereco))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return " " + dscLogradouro + " - CEP " + CEP;
	}
	
	
	
}
